﻿// <copyright file="UV4SourceFilesParser.cs" company="Horiba Medical">
//     Copyright (c) Horiba Medical. All rights reserved.
// </copyright>
// <summary>
//     Provides a source files parser for UV4 project files.
// </summary>

namespace DoxyOutParser.CodeCheck
{
	using System.Collections.Generic;
	using System.Collections.ObjectModel;
	using System.Xml;

	/// <summary>
	/// Parses a UV4 project file to extract the C source files specified within it.
	/// </summary>
	public class UV4SourceFilesParser : ISourceFilesParser
	{
		/// <summary>
		/// The file which needs parsing.
		/// </summary>
		private string uv4ProjectFile;

		/// <summary>
		/// Initializes a new instance of the UV4SourceFilesParser class.
		/// </summary>
		/// <param name="projectFile">Path to the UV4 project file which needs parsing.</param>
		public UV4SourceFilesParser(string projectFile)
		{
			// TODO Check the value of string and eventually check if exist or not.
			this.uv4ProjectFile = projectFile;
		}

		#region ISourceFilesParser Members

		/// <summary>
		/// Gets the list of source files specified in the project file.
		/// </summary>
		/// <value>No set available.</value>
		/// <returns>The generated list.</returns>
		public List<string> SourceFilesList
		{
			get
			{
				List<string> sourceFilesList = new List<string>();

				// Using XML document
				XmlDocument uv4Proj = new XmlDocument();
				uv4Proj.Load(this.uv4ProjectFile);

				XmlNodeList xmlIncludeElementNodeList = uv4Proj.GetElementsByTagName("FilePath");
				foreach (XmlNode xmlNode in xmlIncludeElementNodeList)
				{
					if (xmlNode.InnerText.Contains(".s") == false)
					{
						sourceFilesList.Add(xmlNode.InnerText);
					}
				}

				return sourceFilesList;
			}
		}

		#endregion
	}
}
